/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić                    *
 *   ivasic@gmail.com                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BNODE_H
#define BNODE_H

#include <QtGlobal>
		
class QByteArray;

/**
 * @class BNode
 * 
 * Bazna klasa koja predstavlja čvor za B-Encoding.
 * 
 * @author Ivan Vasić <ivasic@gmail.com>
*/
class BNode
{
	public:

		/**
		 * @enum Type
		 * Enumeracija: tip čvora.
		 */
		enum Type
		{
			VALUE, DICT, LIST
		};
		
		/**
		 * @brief Default konstruktor.
		 * Postavlja offset i tip cvora.
		 */
		BNode(quint32 offset, Type type);
		virtual ~BNode();
		
		/**
		 * @brief Vraća tip čvora.
		 */
		Type getType() const { return m_type; }
		
		/**
		 * @brief Vraća offset.
		 */
		quint32 offset() const { return m_offset; }	

		/**
		 * @brief Postavlja dužinu ovog čvora u bajtovima.
		 * 
		 * @warning U veličinu je uračunat i B-Encoding!!! Npr. 4:eggs vraća 6, ili za d4:eggse vraća 8.
		 */
		void setLength(const quint32 val);
		
		/**
		 * @brief Vraća veličinu čvora u bajtovima.
		 * 
		 * @warning U veličinu je uračunat i B-Encoding!!!
		 */
		quint32 length() const { return m_length; }
	

	private:
		///Tip čvora.
		Type m_type;
		
		/**
		 * Offset pozicije ovog čvora u odnosu na početak kodiranog niza.
		 */
		quint32 m_offset;
		
		///Veličina niza u bajtovima sa uračunatim (pre)postfiskima B-Encodinga.
		quint32 m_length;
};

#endif
